import SealMessage from './message.vue'
import {h,render} from 'vue'
// 封装函数
// <SealMessage type="success">登录成功</SealMessage>

type Props = {
    type: 'success' | 'error' | 'warning'
    text: string,
    duration?:number
}

const container = document.createElement("div")
container.setAttribute("class","container-box")
document.body.appendChild(container)

export default function Message({type,text,duration=3000}:Props){
    const vNode = h(SealMessage,{type},text)
    render(vNode,container)

    // 清除元素组件： render(null,document.body)
    setTimeout(()=>{
        render(null,container)
    },duration)
}

Message.success = (str:string)=>{
    Message({
        type:'success',
        text:str
    })
}
Message.warning = (str:string)=>{
    Message({
        type:'warning',
        text:str
    })
}
Message.error = (str:string)=>{
    Message({
        type:'error',
        text:str
    })
}
